package written;

/**
 * 评测题目: 1. 反转一个字符串，例如"Welcome to this Javascript Guide!"
 * 将会变成"emocleW ot siht tpircsavaJ !ediuG"
 *
 * @author TANGYE
 * @date 2021-01-02 10:50
 **/

public class QuestionThree {

    public static String coverOne(String str) {
        if (null == str || "".equals(str)) {
            throw new RuntimeException("param is empty");
        }
        char[] arr = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = arr.length - 1; i >= 0; i--) {
            sb.append(arr[i]);
        }
        return sb.toString();
    }

    public static String coverAll(String str) {
        if (null == str || "".equals(str)) {
            throw new RuntimeException("param is empty");
        }
        if (str.indexOf(" ") == -1) {
            throw new RuntimeException("param error rule");
        }
        StringBuilder sb = new StringBuilder();
        String[] strArr = str.split(" ");
        String cover = null;
        for (int i = 0; i < strArr.length; i++) {
            cover = coverOne(strArr[i]);
            if (i != strArr.length - 1) {
                sb.append(cover).append(" ");
            }
        }
        sb.append(cover);
        return sb.toString();
    }

    public static void main(String[] args) {
        String coverStr = coverAll("Welcome to this Javascript Guide!");
        System.out.println(coverStr);
    }
}
